// mircoApp/cloud_shop/brand_source_material/brand_source_material.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    hideTxt: true,
    active: 0,
    infoData: [],
    page: 1,
    total_page: 0,
    isLoadMore: true,
    cateList: [],
    dataList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getCate();
    this.getData();
  },
  tabChange(e) {
    this.setData({
      active: e.detail.name,
    });
    this.init();
    this.getGood();
  },
  init() {
    this.setData({
      page: 1,
      total_page: 0,
      isLoadMore: true,
      dataList: [],
    });
  },
  toDetail(e) {
    let { id } = e.currentTarget.dataset;
    wx.navigateTo({
      url:
        "/mircoApp/cloud_shop/brand_source_detail/brand_source_detail?id=" + id,
    });
  },
  async getCate() {
    let { data } = await app._postNetWork({
      url: app.getNetAddresss(
        "plugin.material-center.api.centerlist.firstCategoryList"
      ),
      data: {
        brand_id: this.options.id,
      },
    });
    if (data.result) {
      this.setData({
        cateList: data.data,
      });
      this.init();
      this.getGood();
    } else {
      app.tips(data.msg);
    }
  },
  async getData() {
    let { data } = await app._postNetWork({
      url: app.getNetAddresss("plugin.cloud-shop.frontend.brand.index"),
      data: {
        brand_id: this.options.id,
      },
    });
    if (data.result) {
      this.setData({
        infoData: data.data,
      });
    } else {
      app.tips(data.msg);
    }
  },
  async getGood() {
    let json = {
      brand_id: this.options.id,
    };
    if (this.data.active) {
      json.parentid = this.data.active;
    }
    let { data } = await app._postNetWork({
      url: app.getNetAddresss("plugin.material-center.api.centerlist.index"),
      data: json,
    });
    if (data.result) {
      this.setData({
        dataList: data.data.list.data,
        total_page: data.data.list.last_page,
        isLoadMore: true,
      });
      console.log('sssssssss',this.data.dataList)
    } else {
      app.tips(msg);
    }
  },
  async getMoreData() {
    if (!this.data.isLoadMore) return;
    this.data.isLoadMore = false; // 防止多次请求分页数据
    if (this.data.page >= this.data.total_page) {
      return;
    } else {
      this.setData({
        page: this.data.page,
      });
      let json = {
        page: this.data.page,
        brand_id: this.options.id,
      };
      if (this.data.active) {
        json.parentid = this.data.active;
      }
      let { data } = await app._postNetWork({
        url: app.getNetAddresss("plugin.material-center.api.centerlist.index"),
        data: json,
      });
      if (data.result) {
        this.setData({
          dataList: this.data.dataList.concat(data.data.list.data),
        });
      } else {
        app.tips(data.msg);
      }
    }
  },
  copuM(e) {
    let { info } = e.currentTarget.dataset;
    wx.setClipboardData({
      data: info,
      success(res) {
        app.tips("复制成功");
      },
    });
  },
  bandDetailShowOpen() {
    this.setData({
      bandDetailShow: true,
    });
  },
  taphideTxt() {
    this.setData({
      hideTxt: !this.data.hideTxt,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
